<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "yyh_log".
 *
 * @property int $id
 * @property int $user_id 员工
 * @property string $menu_url 页面
 * @property string $cip IP
 * @property string $createtime 创建时间
 */
class Log extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'yyh_log';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id', 'menu_url', 'cip', 'createtime'], 'required'],
            [['user_id'], 'integer'],
            [['createtime'], 'safe'],
            [['menu_url'], 'string', 'max' => 64],
            [['cip'], 'string', 'max' => 32],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '员工',
            'menu_url' => '页面',
            'cip' => 'IP',
            'createtime' => '创建时间',
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function getMenu_name()
    {
        return Menu::find()->where("url = '{$this->menu_url}'")->one()->name;
    }

    public function getUsername()
    {
        return User::find()->where("id = {$this->user_id}")->one()->showname;
    }
}
